<template>
  <div class="goods-hot">
    <h3>{{ titleObj[type] }}</h3>
    <!-- 商品区块 -->
    <goods-item v-for="good in goodList" :good="good" :key="good.id" />
  </div>
</template>
<script>
import GoodsItem from '@/views/Category/components/second-food.vue'
import { findHotGoods } from '@/api/good'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  components: {
    GoodsItem
  },
  props: {
    type: {
      type: Number,
      default: 1
    }
  },
  setup (props) {
    const titleObj = { 1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜' }

    const goodList = ref([])
    const route = useRoute()
    const getGoodList = async () => {
      const res = await findHotGoods({
        id: route.params.id,
        type: props.type
      })
      console.log(res)
      goodList.value = res.result
    }

    onMounted(() => {
      getGoodList()
    })

    return { titleObj, goodList }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
